package com.example.studentmanager;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class DeleteStudent extends AppCompatActivity {
    EditText deleteByxuehao;
    Button btndelete;
    StudentDB studentDB;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_delete_student);

        deleteByxuehao = findViewById(R.id.deleteByxuehao);
        btndelete = findViewById(R.id.btndelete);
        studentDB = StudentDB.getStudentDB(DeleteStudent.this);
        Intent intent = getIntent();
        String yy = intent.getStringExtra("yy").substring(4);
        deleteByxuehao.setText(yy);

        btndelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                boolean succes;
                succes = studentDB.deleteById(deleteByxuehao.getText().toString());
                if (succes) {
                    Toast.makeText(DeleteStudent.this, "删除成功", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(DeleteStudent.this, "删除失败，学号不存在！", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}